<template>
    <!-- 对话框表单 -->
    <!-- 建议使用 Prettier 格式化代码 -->
    <!-- el-form 内可以混用 el-form-item、FormItem、ba-input 等输入组件 -->
    <el-dialog
        class="ba-operate-dialog"
        :close-on-click-modal="false"
        :model-value="['Add', 'Edit'].includes(baTable.form.operate!)"
        @close="baTable.toggleForm"
        width="50%"
    >
        <template #header>
            <div class="title" v-drag="['.ba-operate-dialog', '.el-dialog__header']" v-zoom="'.ba-operate-dialog'">
                {{ baTable.form.operate ? t(baTable.form.operate) : '' }}
            </div>
        </template>
        <el-scrollbar v-loading="baTable.form.loading" class="ba-table-form-scrollbar">
            <div
                class="ba-operate-form"
                :class="'ba-' + baTable.form.operate + '-form'"
                :style="config.layout.shrink ? '':'width: calc(100% - ' + baTable.form.labelWidth! / 2 + 'px)'"
            >
                <el-form
                    v-if="!baTable.form.loading"
                    ref="formRef"
                    @submit.prevent=""
                    @keyup.enter="baTable.onSubmit(formRef)"
                    :model="baTable.form.items"
                    :label-position="config.layout.shrink ? 'top' : 'right'"
                    :label-width="baTable.form.labelWidth + 'px'"
                    :rules="rules"
                >
                    <FormItem :label="t('poolLogOrder.user_id')" type="remoteSelect" v-model="baTable.form.items!.user_id" prop="user_id" :input-attr="{ pk: 'xxz_user.id', field: 'nickname', 'remote-url': '/admin/user.User/index' }" :placeholder="t('Please select field', { field: t('poolLogOrder.user_id') })" />
                    <FormItem :label="t('poolLogOrder.shop_id')" type="remoteSelect" v-model="baTable.form.items!.shop_id" prop="shop_id" :input-attr="{ pk: 'xxz_shop.id', field: 'name', 'remote-url': '/admin/Shop/index' }" :placeholder="t('Please select field', { field: t('poolLogOrder.shop_id') })" />
                    <FormItem :label="t('poolLogOrder.order_id')" type="remoteSelect" v-model="baTable.form.items!.order_id" prop="order_id" :input-attr="{ pk: 'xxz_order.id', field: 'order_no', 'remote-url': '/admin/Order/index' }" :placeholder="t('Please select field', { field: t('poolLogOrder.order_id') })" />
                    <FormItem :label="t('poolLogOrder.ordergoods_id')" type="remoteSelect" v-model="baTable.form.items!.ordergoods_id" prop="ordergoods_id" :input-attr="{ pk: 'xxz_ordergoods.id', field: 'name', 'remote-url': '/admin/Ordergoods/index' }" :placeholder="t('Please select field', { field: t('poolLogOrder.ordergoods_id') })" />
                    <FormItem :label="t('poolLogOrder.price')" type="number" prop="price" :input-attr="{ step: 1 }" v-model.number="baTable.form.items!.price" :placeholder="t('Please input field', { field: t('poolLogOrder.price') })" />
                    <FormItem :label="t('poolLogOrder.total_price')" type="number" prop="total_price" :input-attr="{ step: 1 }" v-model.number="baTable.form.items!.total_price" :placeholder="t('Please input field', { field: t('poolLogOrder.total_price') })" />
                    <FormItem :label="t('poolLogOrder.cost_price')" type="number" prop="cost_price" :input-attr="{ step: 1 }" v-model.number="baTable.form.items!.cost_price" :placeholder="t('Please input field', { field: t('poolLogOrder.cost_price') })" />
                    <FormItem :label="t('poolLogOrder.total_cost_price')" type="number" prop="total_cost_price" :input-attr="{ step: 1 }" v-model.number="baTable.form.items!.total_cost_price" :placeholder="t('Please input field', { field: t('poolLogOrder.total_cost_price') })" />
                    <FormItem :label="t('poolLogOrder.num')" type="number" prop="num" :input-attr="{ step: 1 }" v-model.number="baTable.form.items!.num" :placeholder="t('Please input field', { field: t('poolLogOrder.num') })" />
                    <FormItem :label="t('poolLogOrder.coin_num')" type="number" prop="coin_num" :input-attr="{ step: 1 }" v-model.number="baTable.form.items!.coin_num" :placeholder="t('Please input field', { field: t('poolLogOrder.coin_num') })" />
                    <FormItem :label="t('poolLogOrder.get_coin_num')" type="number" prop="get_coin_num" :input-attr="{ step: 1 }" v-model.number="baTable.form.items!.get_coin_num" :placeholder="t('Please input field', { field: t('poolLogOrder.get_coin_num') })" />
                    <FormItem :label="t('poolLogOrder.back_buy_money')" type="number" prop="back_buy_money" :input-attr="{ step: 1 }" v-model.number="baTable.form.items!.back_buy_money" :placeholder="t('Please input field', { field: t('poolLogOrder.back_buy_money') })" />
                    <FormItem :label="t('poolLogOrder.get_back_buy_money')" type="number" prop="get_back_buy_money" :input-attr="{ step: 1 }" v-model.number="baTable.form.items!.get_back_buy_money" :placeholder="t('Please input field', { field: t('poolLogOrder.get_back_buy_money') })" />
                    <FormItem :label="t('poolLogOrder.residue_back_buy_money')" type="number" prop="residue_back_buy_money" :input-attr="{ step: 1 }" v-model.number="baTable.form.items!.residue_back_buy_money" :placeholder="t('Please input field', { field: t('poolLogOrder.residue_back_buy_money') })" />
                    <FormItem :label="t('poolLogOrder.directly_return_money')" type="number" prop="directly_return_money" :input-attr="{ step: 1 }" v-model.number="baTable.form.items!.directly_return_money" :placeholder="t('Please input field', { field: t('poolLogOrder.directly_return_money') })" />
                    <FormItem :label="t('poolLogOrder.get_directly_return_money')" type="number" prop="get_directly_return_money" :input-attr="{ step: 1 }" v-model.number="baTable.form.items!.get_directly_return_money" :placeholder="t('Please input field', { field: t('poolLogOrder.get_directly_return_money') })" />
                    <FormItem :label="t('poolLogOrder.commission_than')" type="number" prop="commission_than" :input-attr="{ step: 1 }" v-model.number="baTable.form.items!.commission_than" :placeholder="t('Please input field', { field: t('poolLogOrder.commission_than') })" />
                    <FormItem :label="t('poolLogOrder.commission_money')" type="number" prop="commission_money" :input-attr="{ step: 1 }" v-model.number="baTable.form.items!.commission_money" :placeholder="t('Please input field', { field: t('poolLogOrder.commission_money') })" />
                    <FormItem :label="t('poolLogOrder.commission_earnings')" type="number" prop="commission_earnings" :input-attr="{ step: 1 }" v-model.number="baTable.form.items!.commission_earnings" :placeholder="t('Please input field', { field: t('poolLogOrder.commission_earnings') })" />
                    <FormItem :label="t('poolLogOrder.push_than')" type="number" prop="push_than" :input-attr="{ step: 1 }" v-model.number="baTable.form.items!.push_than" :placeholder="t('Please input field', { field: t('poolLogOrder.push_than') })" />
                    <FormItem :label="t('poolLogOrder.push_money')" type="number" prop="push_money" :input-attr="{ step: 1 }" v-model.number="baTable.form.items!.push_money" :placeholder="t('Please input field', { field: t('poolLogOrder.push_money') })" />
                    <FormItem :label="t('poolLogOrder.push_send_money')" type="number" prop="push_send_money" :input-attr="{ step: 1 }" v-model.number="baTable.form.items!.push_send_money" :placeholder="t('Please input field', { field: t('poolLogOrder.push_send_money') })" />
                    <FormItem :label="t('poolLogOrder.push_user_ids')" type="remoteSelects" v-model="baTable.form.items!.push_user_ids" prop="push_user_ids" :input-attr="{ pk: 'xxz_.id', field: 'name', 'remote-url': '' }" :placeholder="t('Please select field', { field: t('poolLogOrder.push_user_ids') })" />
                    <FormItem :label="t('poolLogOrder.push_back')" type="number" prop="push_back" :input-attr="{ step: 1 }" v-model.number="baTable.form.items!.push_back" :placeholder="t('Please input field', { field: t('poolLogOrder.push_back') })" />
                    <FormItem :label="t('poolLogOrder.shop_push_than')" type="number" prop="shop_push_than" :input-attr="{ step: 1 }" v-model.number="baTable.form.items!.shop_push_than" :placeholder="t('Please input field', { field: t('poolLogOrder.shop_push_than') })" />
                    <FormItem :label="t('poolLogOrder.shop_push_money')" type="number" prop="shop_push_money" :input-attr="{ step: 1 }" v-model.number="baTable.form.items!.shop_push_money" :placeholder="t('Please input field', { field: t('poolLogOrder.shop_push_money') })" />
                    <FormItem :label="t('poolLogOrder.shop_push_send_money')" type="number" prop="shop_push_send_money" :input-attr="{ step: 1 }" v-model.number="baTable.form.items!.shop_push_send_money" :placeholder="t('Please input field', { field: t('poolLogOrder.shop_push_send_money') })" />
                    <FormItem :label="t('poolLogOrder.shop_push_user_id')" type="remoteSelect" v-model="baTable.form.items!.shop_push_user_id" prop="shop_push_user_id" :input-attr="{ pk: 'xxz_.id', field: 'name', 'remote-url': '' }" :placeholder="t('Please select field', { field: t('poolLogOrder.shop_push_user_id') })" />
                    <FormItem :label="t('poolLogOrder.shop_push_back')" type="number" prop="shop_push_back" :input-attr="{ step: 1 }" v-model.number="baTable.form.items!.shop_push_back" :placeholder="t('Please input field', { field: t('poolLogOrder.shop_push_back') })" />
                    <FormItem :label="t('poolLogOrder.shop_indirect_than')" type="number" prop="shop_indirect_than" :input-attr="{ step: 1 }" v-model.number="baTable.form.items!.shop_indirect_than" :placeholder="t('Please input field', { field: t('poolLogOrder.shop_indirect_than') })" />
                    <FormItem :label="t('poolLogOrder.shop_indirect_money')" type="number" prop="shop_indirect_money" :input-attr="{ step: 1 }" v-model.number="baTable.form.items!.shop_indirect_money" :placeholder="t('Please input field', { field: t('poolLogOrder.shop_indirect_money') })" />
                    <FormItem :label="t('poolLogOrder.shop_indirect_send_money')" type="number" prop="shop_indirect_send_money" :input-attr="{ step: 1 }" v-model.number="baTable.form.items!.shop_indirect_send_money" :placeholder="t('Please input field', { field: t('poolLogOrder.shop_indirect_send_money') })" />
                    <FormItem :label="t('poolLogOrder.shop_indirect_user_ids')" type="remoteSelects" v-model="baTable.form.items!.shop_indirect_user_ids" prop="shop_indirect_user_ids" :input-attr="{ pk: 'xxz_.id', field: 'name', 'remote-url': '' }" :placeholder="t('Please select field', { field: t('poolLogOrder.shop_indirect_user_ids') })" />
                    <FormItem :label="t('poolLogOrder.shop_indirect_back')" type="number" prop="shop_indirect_back" :input-attr="{ step: 1 }" v-model.number="baTable.form.items!.shop_indirect_back" :placeholder="t('Please input field', { field: t('poolLogOrder.shop_indirect_back') })" />
                    <FormItem :label="t('poolLogOrder.coin_than')" type="number" prop="coin_than" :input-attr="{ step: 1 }" v-model.number="baTable.form.items!.coin_than" :placeholder="t('Please input field', { field: t('poolLogOrder.coin_than') })" />
                    <FormItem :label="t('poolLogOrder.coin_money')" type="number" prop="coin_money" :input-attr="{ step: 1 }" v-model.number="baTable.form.items!.coin_money" :placeholder="t('Please input field', { field: t('poolLogOrder.coin_money') })" />
                    <FormItem :label="t('poolLogOrder.back_than')" type="number" prop="back_than" :input-attr="{ step: 1 }" v-model.number="baTable.form.items!.back_than" :placeholder="t('Please input field', { field: t('poolLogOrder.back_than') })" />
                    <FormItem :label="t('poolLogOrder.back_money')" type="number" prop="back_money" :input-attr="{ step: 1 }" v-model.number="baTable.form.items!.back_money" :placeholder="t('Please input field', { field: t('poolLogOrder.back_money') })" />
                    <FormItem :label="t('poolLogOrder.back_total')" type="number" prop="back_total" :input-attr="{ step: 1 }" v-model.number="baTable.form.items!.back_total" :placeholder="t('Please input field', { field: t('poolLogOrder.back_total') })" />
                    <FormItem :label="t('poolLogOrder.shop_money')" type="number" prop="shop_money" :input-attr="{ step: 1 }" v-model.number="baTable.form.items!.shop_money" :placeholder="t('Please input field', { field: t('poolLogOrder.shop_money') })" />
                    <FormItem :label="t('poolLogOrder.status')" type="number" v-model="baTable.form.items!.status" prop="status" :data="{ content: { '1': t('poolLogOrder.status 1'), '2': t('poolLogOrder.status 2') } }" :placeholder="t('Please input field', { field: t('poolLogOrder.status') })" />
                    <FormItem :label="t('poolLogOrder.back_status')" type="radio" v-model="baTable.form.items!.back_status" prop="back_status" :data="{ content: { '1': t('poolLogOrder.back_status 1'), '2': t('poolLogOrder.back_status 2') } }" :placeholder="t('Please select field', { field: t('poolLogOrder.back_status') })" />
                    <FormItem :label="t('poolLogOrder.coin_status')" type="radio" v-model="baTable.form.items!.coin_status" prop="coin_status" :data="{ content: { '1': t('poolLogOrder.coin_status 1'), '2': t('poolLogOrder.coin_status 2') } }" :placeholder="t('Please select field', { field: t('poolLogOrder.coin_status') })" />
                    <FormItem :label="t('poolLogOrder.commission_time')" type="number" prop="commission_time" :input-attr="{ step: 1 }" v-model.number="baTable.form.items!.commission_time" :placeholder="t('Please input field', { field: t('poolLogOrder.commission_time') })" />
                </el-form>
            </div>
        </el-scrollbar>
        <template #footer>
            <div :style="'width: calc(100% - ' + baTable.form.labelWidth! / 1.8 + 'px)'">
                <el-button @click="baTable.toggleForm()">{{ t('Cancel') }}</el-button>
                <el-button v-blur :loading="baTable.form.submitLoading" @click="baTable.onSubmit(formRef)" type="primary">
                    {{ baTable.form.operateIds && baTable.form.operateIds.length > 1 ? t('Save and edit next item') : t('Save') }}
                </el-button>
            </div>
        </template>
    </el-dialog>
</template>

<script setup lang="ts">
import type { FormInstance, FormItemRule } from 'element-plus'
import { inject, reactive, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import FormItem from '/@/components/formItem/index.vue'
import { useConfig } from '/@/stores/config'
import type baTableClass from '/@/utils/baTable'
import { buildValidatorData } from '/@/utils/validate'

const config = useConfig()
const formRef = ref<FormInstance>()
const baTable = inject('baTable') as baTableClass

const { t } = useI18n()

const rules: Partial<Record<string, FormItemRule[]>> = reactive({
    price: [buildValidatorData({ name: 'number', title: t('poolLogOrder.price') })],
    total_price: [buildValidatorData({ name: 'number', title: t('poolLogOrder.total_price') })],
    cost_price: [buildValidatorData({ name: 'number', title: t('poolLogOrder.cost_price') })],
    total_cost_price: [buildValidatorData({ name: 'number', title: t('poolLogOrder.total_cost_price') })],
    num: [buildValidatorData({ name: 'number', title: t('poolLogOrder.num') })],
    coin_num: [buildValidatorData({ name: 'number', title: t('poolLogOrder.coin_num') })],
    get_coin_num: [buildValidatorData({ name: 'number', title: t('poolLogOrder.get_coin_num') })],
    back_buy_money: [buildValidatorData({ name: 'number', title: t('poolLogOrder.back_buy_money') })],
    get_back_buy_money: [buildValidatorData({ name: 'number', title: t('poolLogOrder.get_back_buy_money') })],
    residue_back_buy_money: [buildValidatorData({ name: 'number', title: t('poolLogOrder.residue_back_buy_money') })],
    directly_return_money: [buildValidatorData({ name: 'number', title: t('poolLogOrder.directly_return_money') })],
    get_directly_return_money: [buildValidatorData({ name: 'number', title: t('poolLogOrder.get_directly_return_money') })],
    commission_than: [buildValidatorData({ name: 'number', title: t('poolLogOrder.commission_than') })],
    commission_money: [buildValidatorData({ name: 'number', title: t('poolLogOrder.commission_money') })],
    commission_earnings: [buildValidatorData({ name: 'number', title: t('poolLogOrder.commission_earnings') })],
    push_than: [buildValidatorData({ name: 'number', title: t('poolLogOrder.push_than') })],
    push_money: [buildValidatorData({ name: 'number', title: t('poolLogOrder.push_money') })],
    push_send_money: [buildValidatorData({ name: 'number', title: t('poolLogOrder.push_send_money') })],
    push_back: [buildValidatorData({ name: 'number', title: t('poolLogOrder.push_back') })],
    shop_push_than: [buildValidatorData({ name: 'number', title: t('poolLogOrder.shop_push_than') })],
    shop_push_money: [buildValidatorData({ name: 'number', title: t('poolLogOrder.shop_push_money') })],
    shop_push_send_money: [buildValidatorData({ name: 'number', title: t('poolLogOrder.shop_push_send_money') })],
    shop_push_back: [buildValidatorData({ name: 'number', title: t('poolLogOrder.shop_push_back') })],
    shop_indirect_than: [buildValidatorData({ name: 'number', title: t('poolLogOrder.shop_indirect_than') })],
    shop_indirect_money: [buildValidatorData({ name: 'number', title: t('poolLogOrder.shop_indirect_money') })],
    shop_indirect_send_money: [buildValidatorData({ name: 'number', title: t('poolLogOrder.shop_indirect_send_money') })],
    shop_indirect_back: [buildValidatorData({ name: 'number', title: t('poolLogOrder.shop_indirect_back') })],
    coin_than: [buildValidatorData({ name: 'number', title: t('poolLogOrder.coin_than') })],
    coin_money: [buildValidatorData({ name: 'number', title: t('poolLogOrder.coin_money') })],
    back_than: [buildValidatorData({ name: 'number', title: t('poolLogOrder.back_than') })],
    back_money: [buildValidatorData({ name: 'number', title: t('poolLogOrder.back_money') })],
    back_total: [buildValidatorData({ name: 'number', title: t('poolLogOrder.back_total') })],
    shop_money: [buildValidatorData({ name: 'number', title: t('poolLogOrder.shop_money') })],
    status: [buildValidatorData({ name: 'number', title: t('poolLogOrder.status') })],
    commission_time: [buildValidatorData({ name: 'number', title: t('poolLogOrder.commission_time') })],
    create_time: [buildValidatorData({ name: 'date', title: t('poolLogOrder.create_time') })],
    update_time: [buildValidatorData({ name: 'date', title: t('poolLogOrder.update_time') })],
})
</script>

<style scoped lang="scss"></style>
